<template>
  <div style="display:inline">
    <a-button type="primary" icon="vertical-align-top" size="large" @click="onImportData">导入商品目录</a-button>
    <import-excel ref="import" @onSubmit="onSubmitExcel">
      <!-- <template #cusBtn>
            <export-excel ref="export" btnType="default" btnText="下载模板" @getExcelData="onDownloadDemo"></export-excel>
        </template> -->
    </import-excel>
    <div class="banOpt" v-show="isBanOpt"></div>
  </div>
</template>

<script>
import importExcel from '@/views/app/biz/common/importExcel'
import exportExcel from '@/views/app/biz/common/exportExcel/index.vue'
import { fileUpload } from './upload'
export default {
  name: 'importHospitalStore',
  components: {
    importExcel,
    exportExcel
  },
  data() {
    return {
      isBanOpt:false
    }
  },
  methods: {
    onDownloadDemo() {
      //x下载模板，如需请求数据，则在此请求数据后执行以下
      this.$emit('onDownloadDemo')
      let listName = '基础商品信息'
      let listHeader = [
        '商品自编码',
        '商品名称',
        '一级分类（学科、品类）',
        '二级分类（用途、品目）',
        '三级分类（部位、功能、品种）',
        '品牌'
      ]
      let listField = ['code', 'productNameZh', 'first', 'second', 'third', 'brand']
      let exportList = []
      this.$refs.export.setData(listName, listHeader, listField, exportList)
    },
    onImportData() {
      //导入excel预览列表的columns,要求title值和excel表头值一一对应
      const excelColumns =[
          // { title: '平台编码', dataIndex: 'code', key: 'code',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '编码', dataIndex: 'standardCode', key: 'standardCode',view:true,require:true, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: 'EDI编码', dataIndex: 'ediCode', key: 'ediCode',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '国家医保代码', dataIndex: 'medicareCode', key: 'medicareCode',view:true,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '省医保代码', dataIndex: 'medicareCode2', key: 'medicareCode2',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '市医保代码', dataIndex: 'medicareCode3', key: 'medicareCode3',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '一级分类', dataIndex: 'first', key: 'first',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '二级分类', dataIndex: 'second', key: 'second',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '三级分类', dataIndex: 'third', key: 'third',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '品名', dataIndex: 'productNameZh', key: 'productNameZh',view:true,require:true, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '通用名', dataIndex: 'commonName', key: 'commonName',view:true,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '价格(元)', dataIndex: 'price', key: 'price',view:true,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '规格', dataIndex: 'spec', key: 'spec',view:true,require:true, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '型号', dataIndex: 'model', key: 'model',view:true,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '描述', dataIndex: 'disc', key: 'disc',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '品牌', dataIndex: 'brand', key: 'brand',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '生产企业社会编码', dataIndex: 'manufacturerCode', key: 'manufacturerCode',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '生产企业中文名称', dataIndex: 'manufacturerZh', key: 'manufacturerZh',view:true,require:true, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '产地', dataIndex: 'origin', key: 'origin',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '产品类别', dataIndex: 'category', key: 'category',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          { title: '计量单位', dataIndex: 'measurement', key: 'measurement',view:true,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '药品本位码', dataIndex: 'sdc', key: 'sdc',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '注册证类型',dataIndex: 'approvalType',key: 'approvalType',view:false,require:false,align: 'center',scopedSlots: { customRender: 'unfilled' } },
          { title: '注册证号', dataIndex: 'approvalNum', key: 'approvalNum',view:true,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '当前有效期始', dataIndex: 'approvalDate', key: 'approvalDate',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '当前有效期止', dataIndex: 'validDate', key: 'validDate',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '结算方式', dataIndex: 'settlement', key: 'settlement',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          // { title: '带量标识', dataIndex: 'bulkFlage', key: 'bulkFlage',view:false,require:false, align: 'center',scopedSlots: { customRender: 'unfilled' }  },
          
        ]
      this.$refs.import.showModal(excelColumns)
    },
    //提交导入数据
    async onSubmitExcel(val) {
      console.log(val)
      //执行提交数据代码，提交成功后执行this.$refs.import.closeModal2()
      const key = 'updatable';
      this.$message.loading({ content: '导入中', key ,duration: 0 })
      this.isBanOpt=true
      let res = await fileUpload(val, {})
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.success({ content: '导入成功', key, duration: 3 })
        this.$refs.import.closeModal2()
        let that=this
        this.$info({
          title: '导入完成',
          content: '成功：'+res.data.insert+' 条；\n更新：'+res.data.update+' 条；\n错误：'+res.data.error+' 条',
          onOk() {
            that.$emit('ok')
          },
        });
      } else {
        this.$message.success({ content: '导入失败，请稍后重试', key, duration: 2 })
      }
      this.isBanOpt=false
    },
    
  }
}
</script>

<style></style>
